package br.ufmg.dcc.vod.remoteworkers.processor;

import java.io.Serializable;

import br.edu.ufcg.lsd.commune.container.servicemanager.ServiceManager;
import br.edu.ufcg.lsd.commune.container.servicemanager.actions.RepeatedAction;
import br.ufmg.dcc.vod.remoteworkers.Result;

public class WorkAction implements RepeatedAction {

	@Override
	public void run(Serializable handler, ServiceManager serviceManager) {
		Processor proxy = (Processor) serviceManager.getObjectDeployment(ProcessorImpl.OBJECT_NAME).getObject();
		WorkHandle handle = (WorkHandle) handler;
		try {
			Result result = handle.getCommand().process();
			proxy.workDone(handle, handle.getCommand().getID(), result, null);
		} catch (Exception e) {
			proxy.workDone(handle, handle.getCommand().getID(), null, e);
		}
	}
	
}